<template>
  <div>
    <h2>注册页面</h2>
    <table border="1">
      <tr>
        <td>用户名</td>
        <td>
          <input type="text" v-model="info.dname">
        </td>
      </tr>
      <tr>
        <td>密码</td>
        <td>
          <input type="password" v-model="info.dpwd">
        </td>
      </tr>
      <tr>
        <td colspan="2">
          <input type="button" value="注册" @click="Add()">
        </td>
      </tr>
    </table>

  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios'
import { useRouter } from 'vue-router';
const router = useRouter()
const info=ref({
  dname:"",
  dpwd:"",
})
const Add=()=>{

  if(info.value.dname==""||info.value.dpwd==""){
    alert("用户名或密码不能为空");
    return;
  }
  axios({
    url:"http://localhost:18964/api/CF/Add",
    method:"post",
    data:info.value
  }).then(res=>{
    console.log(res.data);
    if(res.data==101){
      alert("用户名已重复");
    }
    else if(res.data>0){
      alert("注册成功");
      router.push("LoginView")
    }
    else
    {
      alert("注册失败")
    }
  })
}


</script>

<style scoped>

</style>